package com.xja.manager.framework.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.env.Environment;
import org.springframework.util.StringUtils;
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;


@Configuration
@EnableKnife4j
@Import(BeanValidatorPluginsConfiguration.class)
public class SwaggerConfig {

    @Value("${zhyl.swagger.swagger-path}")
    public String swaggerPath;
    @Value("${zhyl.swagger.title}")
    public String title;
    @Value("${zhyl.swagger.description}")
    public String description;
    @Value("${zhyl.swagger.contact-name}")
    public String contactName;
    @Value("${zhyl.swagger.contact-url}")
    public String contactUrl;
    @Value("${zhyl.swagger.contact-email}")
    public String contactEmail;

    @Bean(value = "defaultApi2")
    public Docket defaultApi2() {
        // 构建API文档  文档类型为swagger2
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                // 配置 api扫描路径
                .apis(RequestHandlerSelectors.basePackage(swaggerPath))
                // 指定路径的设置  any代表所有路径
                .paths(PathSelectors.any())
                // api的基本信息
                .build().apiInfo(new ApiInfoBuilder()
                        // api文档名称
                        .title(title)
                        // api文档描述
                        .description(description)
                        // api文档版本
                        .version("1.0") // 版本
                        // api作者信息
                        .contact(new Contact(contactName,contactUrl,contactEmail))
                        .build());
    }

}
